package com.xxx.common.dto;

import com.xxx.common.utils.FileUtil;
import com.xxx.config.WebConfig;

import lombok.Data;

/**
 * @ClassName: FileInfo 
 * @Description: 文件信息
 */
@Data
public class FileInfo {

	private String name; 			//文件名
	
	private long size;  			//以B为单位
	
	private String originalName;	//原文件名
	
	private  String ext;		    //后缀名
	
	private  String path;			//文件地址
	
	public FileInfo() {
		super();
	}
	
	public FileInfo(String name, String ext, String path) {
		super();
		this.name = name;
		this.ext = ext;
		this.path = path;
	}

	public FileInfo(String name, long size, String originalName, String ext, String path) {
		super();
		this.name = name;
		this.size = size;
		this.originalName = originalName;
		this.ext = ext;
		this.path = path;
	}

	/**
	 * 获取文件的相对路径
	 * @return
	 */
	public String getLocalPath() {
		int len = WebConfig.uploadPath.length();
		if (path.length() > len) {
			return path.substring(len);
		}
		return path;
	}
	
	/**
	 * 获取文件大小,带单位
	 * @return
	 */
	public String getFileSize(){
		return FileUtil.getFileSize(size);
	}
	
}
